package com.waigoulin.domain.vo;

import java.util.HashMap;
import java.util.Map;

/**
 * @FileName WeixinTemplateMessageVO
 * @Description 微信模板消息
 * @Author waigoulin
 * @date 2025-05-14
 **/
public class WeixinTemplateMessageVO {

    // 接收消息的用户 OpenID（微信用户在当前公众号的唯一标识）
    private String touser = "or0Ab6ivwmypESVp_bYuk92T6SvU";
    // 模板消息的 ID（在微信公众平台创建模板后获取的唯一标识）
    private String template_id = "GLlAM-Q4jdgsktdNd35hnEbHVam2mwsW2YWuxDhpQkU";
    // 模板信息的 url
    private String url = "https://weixin.qq.com";
    // 模板消息的具体内容，存储键值对形式的字段数据
    // 外层 key 是模板中的字段名（如 user、ip），内层 Map 包含 "value"（字段名）和 value（字段值）
    private Map<String, Map<String, String>> data = new HashMap<>();

    public WeixinTemplateMessageVO(String touser, String template_id) {
        this.touser = touser;
        this.template_id = template_id;
    }

    public void put(TemplateKey key, String value) {
        data.put(key.getCode(), new HashMap<String, String>() {
            private static final long serialVersionUID = 7092338402387318563L;

            {
                put("value", value);
            }
        });
    }

    public static void put(Map<String, Map<String, String>> data, TemplateKey key, String value) {
        data.put(key.getCode(), new HashMap<String, String>() {
            private static final long serialVersionUID = 7092338402387318563L;

            {
                put("value", value);
            }
        });
    }


    public enum TemplateKey {
        USER("user","用户ID"),
        IP("ip", "登录ip"),
        DISTRICT("district", "登陆地区")
        ;

        private String code;
        private String desc;

        TemplateKey(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }
    }


    public String getTouser() {
        return touser;
    }

    public void setTouser(String touser) {
        this.touser = touser;
    }

    public String getTemplate_id() {
        return template_id;
    }

    public void setTemplate_id(String template_id) {
        this.template_id = template_id;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Map<String, Map<String, String>> getData() {
        return data;
    }

    public void setData(Map<String, Map<String, String>> data) {
        this.data = data;
    }

}


